package postwp.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Properties;
import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;

public class CronWpServlet extends HttpServlet {
	private static ActiveMQConnectionFactory connectionFactory;
	private static Connection connection;
	private static Session session;
	private static Destination destination;
	private static boolean transacted = false;

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
	}

	private static void setUp() throws JMSException, IOException {
		File f = new File("configfeed.properties");
		Properties pro = new Properties();
		FileInputStream in = new FileInputStream(f);
		pro.load(in);
		connectionFactory = new ActiveMQConnectionFactory(
				ActiveMQConnection.DEFAULT_USER,
				ActiveMQConnection.DEFAULT_PASSWORD, "tcp://"
						+ pro.getProperty("server") + ":61616");
		connection = connectionFactory.createConnection();
		connection.start();
		session = connection.createSession(transacted, 1);

		destination = session.createQueue(pro.getProperty("queue"));
	}

	private static void createProducerAndSendAMessage(String str)
			throws JMSException {
		MessageProducer producer = session.createProducer(destination);
		producer.setDeliveryMode(1);
		TextMessage message = session.createTextMessage(str);
		System.out.println("Sending message: " + message.getText());
		producer.send(message);
	}
}